{include file="public/header"/}
<link rel="stylesheet" href="{__PUBLIC_PATH}/admin/pcf/pcfcms.css?v={$version}"/>
</head>
<body>
<style type="text/css">
.hDiv{background-color:#f7f7f7;clear:both;border:1px solid #f7f7f7;border-bottom:none;margin-bottom:20px;}
.pcfts{font: bold 14px/20px tahoma,verdana;color:#F60;vertical-align:middle;display:inline-block;margin-right:5px;margin-left:-14px;}
.anchor-icon{display:inline-block;width: 22px;height: 20px;background-color: red;margin-right: 6px;vertical-align: middle;}
.anchor-icon-biao{background: url(/admin/assets/images/icon-copying-norm.png) no-repeat;}
</style>
<div class="layui-form">
<div class="layui-fluid" style="padding-bottom:83px;border:0;">
<div class="layui-col-sm12">
<div class="layui-card" style="box-shadow:0 0 0 0;">			
	<div class="layui-tab layui-tab-brief" id="pcfsystem">
	<ul class="layui-tab-title" style="background-color:#f2f2f2;">
		<a href="{:url('/system.web/index')}"><li>网站设置</li></a>
		<a href="{:url('/system.web/web2')}"><li>核心设置</li></a>
		<a href="{:url('/system.web/basic')}"><li>附件设置</li></a>
        <a href="{:url('/system.web/weapp_email')}"><li class="layui-this">邮箱配置</li></a>
        <a href="{:url('/system.web/weapp_sms')}"><li>短信配置</li></a>
        <a href="{:url('/system.web/weapp_pay')}" style="display:none;"><li>支付配置</li></a>
        <a href="{:url('/system.web/weapp_social')}" style="display:none;"><li>第三方登录配置</li></a>
	</ul>	
	<div class="layui-card-body">
		<div class="layui-form-item layui-row">
			<form id="sendmail">
				<div class="layui-card-header hDiv">邮件配置</div>
				<div class="layui-form-item">
					<label class="layui-form-label" style="width:100px;">状态</label>
					<div class="layui-input-block">
						<input type="checkbox" name="smtp_syn_weapp" lay-filter="smtp_syn_weapp" value="{$config.smtp_syn_weapp|default='0'}" lay-skin="switch" lay-text="开启|关闭" {notempty name="$config.smtp_syn_weapp"}checked{/notempty}>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label" style="width:100px;"><b class="pcfts">*</b> SMTP服务器</label>
					<div class="layui-input-inline">
						<input type="text" name="smtp_server" id="smtp_server" lay-verify="required" value="{$config.smtp_server}" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label" style="width:100px;"></label>
					<div class="layui-form-inline">发送邮箱的smtp地址，如: smtp.qq.com或smtp.gmail.com</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label" style="width:100px;"><b class="pcfts">*</b> SMTP端口号</label>
					<div class="layui-input-inline">
						<input type="text" name="smtp_port" id="smtp_port" lay-verify="required" value="{$config.smtp_port}" class="layui-input">
					</div>
				</div>	
				<div class="layui-form-item">
					<label class="layui-form-label" style="width:100px;"></label>
					<div class="layui-form-inline">
						<span style="color:red;">注意：如果使用阿里云服务器或Gmail，请将端口设为465，其他的可以尝试端口设为25</span>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label" style="width:100px;"><b class="pcfts">*</b> 邮箱账号</label>
					<div class="layui-input-inline">
						<input type="text" name="smtp_user" id="smtp_user" lay-verify="required" value="{$config.smtp_user}" class="layui-input">
					</div>
				</div>	
				<div class="layui-form-item">
					<label class="layui-form-label" style="width:100px;"><b class="pcfts">*</b> 邮箱授权码</label>
					<div class="layui-input-inline">
						<input type="password" name="smtp_pwd" id="smtp_pwd" lay-verify="required" value="{$config.smtp_pwd}" class="layui-input">
					</div>
				</div>					
				<div class="layui-form-item">
					<label class="layui-form-label" style="width:100px;">测试邮箱</label>
					<div class="layui-input-inline">
						<input type="text" name="smtp_test" id="smtp_test" value="{$config.smtp_test}" class="layui-input">
					</div>
					<button class="layui-btn" lay-submit="sendEmail" lay-filter="sendEmail">发送</button>
				</div>
			</form>
		</div>
	</div>
</div>		
</div>
</div>
<div class="pcfclear"></div>
</div>
<div class="submit-info text-center">
    <button class="layui-btn" lay-submit="emailSubmit" lay-filter="emailSubmit">确认提交</button>
</div>
<div class="pcfclear"></div>
</div>
{include file="public/footer"/}
<script>
    layui.use(['layer', 'form'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        // 监听开关
        form.on('switch', function(data){
            var elemId = data.elem.attributes['lay-filter']['nodeValue'];
            if (data.elem.checked) {
                this.value = 1;
            } else {
                this.value = 0;
            }
            $("#"+elemId).val(this.value);
        });
        //测试发送
		form.on('submit(sendEmail)', function(data) {
			if (data.field.smtp_test == '') {
				layer.msg('接收邮箱的地址不能为空！', {time:1000});
				$('input[name=smtp_test]').focus();
				return false;
			} else {
				layer.msg('正在处理请勿刷新页面', {icon: 16,shade: 0.01,time:3600000});
				$.ajax({
					type: "post",
					data: {email:data.field.smtp_test},
					dataType: 'json',
					url: "{:url('/system.web/send_email')}",
					success: function(res) {
						layer.closeAll();
						if(res.status){
							layer.msg(res.msg, {icon:1,time:1000});
						}else{
						    layer.msg(res.msg, {icon:2,time:1000});
						}
					},
					error: function() {
						layer.closeAll();
						layer.msg("网络中断！", {icon: 2,time:1000});
					}
				})
			}
			return false;
		});
		
        //监听提交
        form.on('submit(emailSubmit)', function(data){
            layer.msg('正在处理请勿刷新页面', {icon: 16,shade: 0.01});
            $.ajax({
                type : 'post',
                url : "{:url('/system.web/weapp_email')}",
                data : $('#sendmail').serialize(),
                dataType : 'json',
                success : function(res){
                    layer.closeAll();
                    if(res.status){
                        layer.msg(res.msg, {icon:1,time:1000}, function(){
                            window.location.reload();
                        });
                    }else{
                       layer.msg(res.msg, {icon:2,time:1000});
                    }
                },
                error: function(e){
                    layer.closeAll();
                    layer.msg("网络中断！", {icon: 2,time:1000});
                }
            });
            return false;
        });
    });
</script>
</body>
</html>